package console;

import com.hse.network.IEndDevice;
import com.hse.network.NetworkFactory;
import com.hse.network.exceptions.NetworkException;

/**
 * Created by IntelliJ IDEA.
 * User: kate
 * Date: 30.05.2009
 * Time: 17:23:00
 * To change this template use File | Settings | File Templates.
 */
public class Client {
    private final static short PAN_ID = (short) 12345;
    private final static String PORT_NUMBER = "COM7";
    private final static Long MAC_ADDRESS = 1L;

    public static void main(String[] args) throws NetworkException, InstantiationException {
        System.out.println("Sample program for testing network layer: client version");
        System.out.println("Creating endDevice...");
        IEndDevice endDevice = NetworkFactory.createEndDevice(PORT_NUMBER, MAC_ADDRESS);
        System.out.println("EndDevice created successfully");
        System.out.println("Trying to connect to server...");
        endDevice.connect(PAN_ID);
        System.out.println("Connection established successfuly");
        System.out.println("Sending 'Hello from client' message to server");
        endDevice.send("Hello from client".getBytes());
        System.out.println("Send finished successfuly...");
        System.out.println("Receving data from server");
        byte[] data = endDevice.recv();
        System.out.println("Reveived data from server: " + new String(data));
        System.out.println("Closing endDevice...");
        endDevice.close();
        System.out.println("Everything worked just fine!");
    }
}
